package com.wanwu.channel.biz;


import com.wanwu.channel.biz.mapper.PayOrderMapper;
import com.wanwu.channel.biz.mapper.ProfitSharingOrderMapper;
import com.wanwu.channel.biz.po.ProfitSharingOrder;
import com.wanwu.channel.model.SettleReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ProfitSharingOrderService {
    @Autowired
    private ProfitSharingOrderMapper tradeOrderMapper;
    @Autowired
    private PayOrderMapper payNotifyMapper;

    public void insert(SettleReq req){
        ProfitSharingOrder profitSharingOrder = new ProfitSharingOrder();
        profitSharingOrder.setSerialNo(req.getSerialNo());
        profitSharingOrder.setPayType(1);
        profitSharingOrder.setPayNo(req.getOutTradeNo());
        profitSharingOrder.setSettleNo(req.getSerialNo());
        profitSharingOrder.setResult(1);
        String accounts = req.getReceivers().stream()
                .map(receiver -> receiver.getAccount()) // 获取每个 Receiver 的 account
                .collect(Collectors.joining(",")); // 使用 "," 作为分隔符连接所有 account
        profitSharingOrder.setReceivers(accounts);
        profitSharingOrder.setUserid(req.getUserId());
        profitSharingOrder.setTotal(req.getTotal());
        profitSharingOrder.setCreateTime(new Date());
        profitSharingOrder.setUpdateTime(new Date());
        tradeOrderMapper.insert(profitSharingOrder);
    }

}

